package com.gzy.cbrsystem.insomnia.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;



public class AuthorityFilter extends StrutsPrepareAndExecuteFilter {

	public void doFilter(ServletRequest request,ServletResponse response,FilterChain next) throws IOException,ServletException{  
		  
		HttpServletRequest req = (HttpServletRequest)request;  
		HttpServletResponse resp = (HttpServletResponse)response;  
		HttpSession session = req.getSession();  
		String requesturi = req.getRequestURI();  
		if(requesturi.endsWith("css")  
		   || requesturi.endsWith("js")  
		   || requesturi.endsWith("login.jsp")  
		   || requesturi.endsWith("Login.action")  
		   || requesturi.endsWith("Logout.action") ){  
		      
		    next.doFilter(request, response);  
		      
		}else if(session.getAttribute("username") == null  ){  
		      System.out.println("not logined");
		    resp.sendRedirect("/error1.jsp");  
		}  
	}
}
